define(["model/model","model/application","model/navbar"], function($model,Application,Navbar){
	
	var account = function(data){
		var _this = this;

		this.formatApps = function(list){
			var apps = [];
			for(var i=0;list&&i<list.length;i++){
				apps[i] = new Application(list[i]);
			}
			return apps;
		}
		
		this.formatNavs = function(list){
			var navs = [];
			for(var i=0;list&&i<list.length;i++){
				if(list[i].status == 1){
					var navs = [],navbars = list[i].navbars;
					for(var j=0;navbars&&j<navbars.length;j++){
						navs[j] = new Navbar(navbars[j]);
					}
					return navs;
				}
			}
		}
		
		if(data){
			//用户名
			this.username = data.username;
			//密码
			this.password = data.password;
			//昵称
			this.alias = data.alias;
			//SeesionID
			this.sessionID = data.sessionID;
			//应用列表
			this.apps = this.formatApps(data.apps);
			//当前角色导航菜单
			this.navs = this.formatNavs(data.apps);
		}
		
		this.toMap = function(){
			return $model.toMap(_this);
		};
		
		this.toString = function(){
			return $model.toString(_this);
		}
	}
	
	return account;
});